import { defineStore } from 'pinia'

// 模拟动态菜单数据
const mockMenu = [
  {
    path: '/system',
    meta: { title: '系统管理', icon: 'SettingOutlined' },
    children: [
      {
        path: 'user',
        component: 'User',
        meta: { title: '用户管理' }
      },
      {
        path: 'role',
        component: 'Role',
        meta: { title: '角色管理' }
      }
    ]
  }
]

export const useAuthStore = defineStore('auth', {
  state: () => ({
    token: localStorage.getItem('token'),
    menuRoutes: [],
    hasRoutes: false
  }),
  
  actions: {
    async login() {
      // 模拟登录请求
      return new Promise(resolve => {
        setTimeout(() => {
          this.token = 'mock-token'
          localStorage.setItem('token', this.token)
          resolve(true)
        }, 500)
      })
    },
    
    async getMenu() {
      // 模拟获取菜单
      return new Promise(resolve => {
        setTimeout(() => {
          this.menuRoutes = mockMenu
          resolve()
        }, 500)
      })
    },
    
    logout() {
      this.token = null
      this.hasRoutes = false
      localStorage.removeItem('token')
    }
  }
})